package com.itheima02;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test02 {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, NoSuchFieldException {

        Class clazz = Class.forName("com.itheima02.Student");

//        Student stu = (Student) clazz.getDeclaredConstructor().newInstance();
//
//        stu.setName("小明");
//        String name = stu.getName();
//        stu.setAge(10);
//        int age = stu.getAge();
//
//        System.out.println(name + "------" + age);
//        System.out.println(stu);


//        Field name = clazz.getDeclaredField("name");
//        Student stu = (Student) clazz.getDeclaredConstructor().newInstance();
//
//        name.setAccessible(true);
//
//        name.set(stu, "小红");
//        Object o = name.get(stu);
//
//        System.out.println(o);


        Method showInfo = clazz.getDeclaredMethod("showInfo");

        Student stu = (Student) clazz.getDeclaredConstructor().newInstance();

        showInfo.invoke(stu);

        System.out.println(stu);

    }
}
